/********************************************************************************
 * Project Name		[JavaEE_Web]
 * File Name     	[UpperCaseTag.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package jsp.tag;

import java.io.IOException;
import java.io.StringWriter;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * 把输入内容变为大写输出的tag, 测试JspFragment
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class UpperCaseTag extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {
		JspFragment bodyContent = this.getJspBody();

		// invoke(writer)
		// writer为标签体内容输出流
		// 若为null, writer = getJspContext().getOut(), 即输出到页面上

		// 利用StringWriter获得标签体的内容, "hello world"
		StringWriter writer = new StringWriter();
		bodyContent.invoke(writer);

		// 把标签体内容改为大写
		String content = writer.toString().toUpperCase();

		// 把内容输出到页面
		this.getJspContext().getOut().print(content);

		// throw new SkipPageException(); // 抛出这个异常可以不执行之后的JSP代码
	}
}
